#include<bits/stdc++.h>
using namespace std;
struct A{
    int c,b,r;
    long long sum;
};
struct A tdpb,tdpr;
queue<struct A>dpb;
queue<struct A>dpr;
int T,n,a[200050],ans;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    for(int T_k=0;T_k<T;T_k++){
        cin>>n;
        ans=0;
        tdpb.b=0;
        tdpb.r=0;
        tdpb.sum=0;
        tdpb.c=0;
        tdpr.b=0;
        tdpr.r=0;
        tdpr.sum=0;
        tdpr.c=0;
        dpb.push(tdpb);
        dpr.push(tdpr);
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        while(!dpb.empty()){
            if(dpb.front().c==n){
                int temp=max(dpb.front().sum,dpr.front().sum);
                ans=max(ans,temp);
                dpb.pop();
                dpr.pop();
                continue;
            }

            int x1=dpb.front().sum,x2=dpr.front().sum;
            if(dpb.front().b==a[dpb.front().c+1]){
                x1+=a[dpb.front().c+1];
            }
            if(dpr.front().b==a[dpr.front().c+1]){
                x2+=a[dpr.front().c+1];
            }
            tdpb.b=a[dpb.front().c+1];
            tdpb.c=dpb.front().c+1;
            if(x1>x2){
                tdpb.sum=x1;
                tdpb.r=dpb.front().r;
                dpb.push(tdpb);
            }
            if(x1<x2){
                tdpb.sum=x2;
                tdpb.r=dpr.front().r;
                dpb.push(tdpb);
            }
            if(x1==x2){
                tdpb.sum=x1;
                tdpb.r=dpb.front().r;
                dpb.push(tdpb);
                tdpb.r=dpr.front().r;
                dpb.push(tdpb);
            }

            x1=dpb.front().sum,x2=dpr.front().sum;
            if(dpb.front().r==a[dpb.front().c+1]){
                x1+=a[dpb.front().c+1];
            }
            if(dpr.front().r==a[dpr.front().c+1]){
                x2+=a[dpr.front().c+1];
            }
            tdpr.r=a[dpb.front().c+1];
            tdpr.c=dpb.front().c+1;
            if(x1>x2){
                tdpr.sum=x1;
                tdpr.b=dpb.front().b;
                dpr.push(tdpr);
            }
            if(x1<x2){
                tdpr.sum=x2;
                tdpr.b=dpr.front().b;
                dpr.push(tdpr);
            }
            if(x1==x2){
                tdpr.sum=x1;
                tdpr.b=dpb.front().b;
                dpr.push(tdpr);
                tdpr.b=dpr.front().b;
                dpr.push(tdpr);
            }
            dpb.pop();
            dpr.pop();
        }
        cout<<ans<<endl;
    }
    return 0;
}
